package org.jeecg.common.Wechat.entity;




import org.jeecg.common.Wechat.util.HttpRequestUtil;

import java.util.List;

/**
 * Created by conan on 2017/6/27.
 */
public class WxTemplate {
    //模板消息的id
    private String template_id;
    //用户openid
    private String touser;
    //url
    private String url;
    //标题颜色
    private String topcolor;
    //详细内容
    //private List<HttpRequestUtil.TemplateData> templateData;
    private List<HttpRequestUtil.TemplateData> data;


    public String getTemplate_id() {
        return template_id;
    }

    public void setTemplate_id(String template_id) {
        this.template_id = template_id;
    }

    public String getTouser() {
        return touser;
    }

    public void setTouser(String touser) {
        this.touser = touser;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getTopcolor() {
        return topcolor;
    }

    public void setTopcolor(String topcolor) {
        this.topcolor = topcolor;
    }

   /* public List<HttpRequestUtil.TemplateData> getTemplateData() {
        return templateData;
    }

    public void setTemplateData(List<HttpRequestUtil.TemplateData> templateData) {
        this.templateData = templateData;
    }
  */

    public List<HttpRequestUtil.TemplateData> getData() {
        return data;
    }

    public void setData(List<HttpRequestUtil.TemplateData> data) {
        this.data = data;
    }

    public String toJSON(){
        StringBuffer buffer=new StringBuffer();
        buffer.append("{");
        buffer.append(String.format("\"touser\":\"%s\"", this.touser)).append(",");
        buffer.append(String.format("\"template_id\":\"%s\"", this.template_id)).append(",");
        buffer.append(String.format("\"url\":\"%s\"", this.url)).append(",");
        buffer.append(String.format("\"topcolor\":\"%s\"", this.topcolor)).append(",");
        buffer.append("\"data\":{");
        HttpRequestUtil.TemplateData param = null;
        for (int i = 0; i < this.data.size(); i++) {
            param = data.get(i);
            // 判断是否追加逗号
            if (i < this.data.size() - 1){

                buffer.append(String.format("\"%s\": {\"value\":\"%s\",\"color\":\"%s\"},", param.getName(), param.getValue(), param.getColor()));
            }else{
                buffer.append(String.format("\"%s\": {\"value\":\"%s\",\"color\":\"%s\"}", param.getName(), param.getValue(), param.getColor()));
            }
        }
        buffer.append("}");
        buffer.append("}");
        return buffer.toString();
    }

}
